﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};

	var cols = [
	{col:{header:'物资编码', width:100, sortable:true, editable:true, hcss:'color:#2E6DA4;',
		editor:new Ext.form.TriggerField({
			maxLength:20,
			editable:false,
			triggerClass:'x-form-search-trigger', 
			onTriggerClick: function() {
				var selcfg = {"pageType":"combogrid", "nodeId":"store_mat", "layoutPage":"/public/layout/layout_tree.js", "sourceField":"", "targetField":"", "whereSql":"", "whereValue":"", "whereType":"", "isSame":"1", "isShowData":"1", "isMoreSelect":"0","isReadonly":"1","queryField":"","likeType":"","fieldName":"store_mat.mat_code"};
				JxSelect.createSelectWin(selcfg, this, 'node_store_indet_editgrid');
			}
		})}, field:{name:'store_mat__mat_code',type:'string'}},
	{col:{header:'*物资名称', width:150, sortable:true, editable:true, hcss:'color:#0077FF;',
		editor:new Ext.form.TriggerField({
			maxLength:50,
			editable:true, allowBlank:false,
			triggerClass:'x-form-search-trigger', 
			onTriggerClick: function() {
				if (this.menu == null) {
					var selcfg = {"pageType":"combogrid", "nodeId":"store_mat", "layoutPage":"/public/layout/layout_tree.js", "sourceField":"store_mat.mat_name", "targetField":"store_indet.mat_name", "whereSql":"", "whereValue":"", "whereType":"", "isSame":"1", "isShowData":"1", "isMoreSelect":"0","isReadonly":"0","queryField":"store_mat.mat_name","likeType":"all","fieldName":"store_indet.mat_name"};
					this.menu = Jxstar.createComboMenu(this);
					JxSelect.createComboGrid(selcfg, this.menu, 'node_store_indet_editgrid');
				}
				this.menu.show(this.el);
			}
		})}, field:{name:'store_indet__mat_name',type:'string'}},
	{col:{header:'型号', width:100, sortable:true}, field:{name:'store_mat__mat_size',type:'string'}},
	{col:{header:'单位', width:55, sortable:true}, field:{name:'store_mat__mat_unit',type:'string'}},
	{col:{header:'*入库数量', width:100, sortable:true, align:'right',
		editable:true, hcss:'color:#0077FF;',
		editor:new Ext.form.NumberField({
			decimalPrecision:6, maxLength:22, allowBlank:false
		}),renderer:JxUtil.formatNumber(6)}, field:{name:'store_indet__in_num',type:'float'}},
	{col:{header:'品牌', width:100, sortable:true, editable:true, hcss:'color:#2E6DA4;',
		editor:new Ext.form.TextField({
			maxLength:50
		})}, field:{name:'store_indet__pina',type:'string'}},
	{col:{header:'单价(元)', width:72, sortable:true, align:'right',renderer:JxUtil.formatNumber(2)}, field:{name:'store_mat__mat_price',type:'float'}},
	{col:{header:'入库金额', width:100, sortable:true, align:'right',
		editable:true, hcss:'color:#2E6DA4;',
		editor:new Ext.form.NumberField({
			maxLength:22
		}),renderer:JxUtil.formatMoney(2)}, field:{name:'store_indet__in_money',type:'float'}},
	{col:{header:'货位', width:100, sortable:true, editable:true, hcss:'color:#2E6DA4;',
		editor:new Ext.form.TextField({
			maxLength:20
		})}, field:{name:'store_indet__local_code',type:'string'}},
	{col:{header:'入库日期', width:154, sortable:true, align:'center',
		editable:true, hcss:'color:#2E6DA4;',
		editor:new Ext.ux.DateTimeField({
			format: 'Y-m-d H:i:s',
			minValue: '1900-01-01'
		}),
		renderer:function(value) {
			return JxUtil.renderDate(value, 'Y-m-d H:i:s');
		}}, field:{name:'store_indet__in_date',type:'date'}},
	{col:{header:'主键', width:100, sortable:true, colindex:10000, hidden:true}, field:{name:'store_indet__indet_id',type:'string'}},
	{col:{header:'入库单ID', width:100, sortable:true, colindex:10000, hidden:true}, field:{name:'store_indet__in_id',type:'string'}},
	{col:{header:'物资ID', width:100, sortable:true, colindex:10000, hidden:true}, field:{name:'store_indet__mat_id',type:'string'}}
	];
	
	config.param = {
		cols: cols,
		sorts: null,
		hasQuery: '1',
		isedit: '1',
		isshow: '1',
		funid: 'store_indet'
	};
	
	config.param.substat = true;

	config.eventcfg = {		
	dataImportParam: function(){
		var pgrid = JxUtil.getParentGrid(this.grid);
        var records = JxUtil.getSelectRows(pgrid);
		if (!JxUtil.selected(records)) return;
        
		var area_name = records[0].get('store_in__in_code');
        var e = encodeURIComponent;
		return {extendParam:'extparam_1='+e(area_name)};
	}
};



config.initpage = function(gridNode){
        var grid = gridNode.page;
    
		//父表格数据判断
		var prec = function(subg, records) {
            if (records.length > 0) return true;
            var pg = JxUtil.getParentGrid(subg);
			var pf = JxUtil.getParentForm(subg);
			var rec = pf.myRecord;
			if (!rec || !rec.get('store_in__in_code')) {
				JxHint.alert('没有找到当前表单数据对象！');
				return false;
			}
			pg.getStore().insert(0, rec);
			pg.getSelectionModel().selectFirstRow();
			
			records[0] = rec;
			return true;
		};
    	
        var calu = function(record, field1, field2, field3) {
            var value = record.get(field1) * record.get(field2);
            record.set(field3, value);
        };

        grid.on('beforeedit', function(e) {	
            var pg = JxUtil.getParentGrid(grid);
            var records = pg.getSelectionModel().getSelections();
            
            if (!prec(grid, records)) return false;
            
           // alert(records[0]);
            
            
            //alert('beforeedit='+records.length);
        });

        grid.on('afteredit', function(e) {	
            var pg = JxUtil.getParentGrid(grid);
            var records = pg.getSelectionModel().getSelections();
           // alert('afteredit='+records.length);
            
            if (e.field == 'store_indet__in_num') {
                calu(e.record, 'store_indet__in_num', 'store_mat__mat_price', 'store_indet__in_money');
            }
        });

    };
		
	return new Jxstar.GridNode(config);
}